package cn.itcast.bos.mq;

import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.MessageListener;

import org.springframework.stereotype.Service;

@Service("smsConsumer")
public class SmsConsumer implements MessageListener{

	@Override
	public void onMessage(Message message) {
		MapMessage mapMessage = (MapMessage)message;
		try {
			//模拟发送成功,先不调用吉信通
			String result = "000/xxx";
			if (result.startsWith("000")) {
				//发送成功
				System.out.println("发送短信成功,手机号:"+mapMessage.getString("telephone")+",验证码:"+mapMessage.getString("msg"));
			}else{
				//发送失败
				throw new RuntimeException("短信发送失败,信息码为:"+result);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
